const ora = require("ora");

async function sleep(n){
    return new Promise((resolve,reject)=>setTimeout(resolve,n));
}
// laoding
async function wrapLoading(fn, message,...args) {
    const spinner = ora(message);
    spinner.start(); // 开启加载状态
    try {
      let repos = await fn(...args);
      spinner.succeed(); // 成功
      return repos;
    } catch (e) {
        spinner.fail('加载失败。。。')
        await sleep(2000) // 2s之后递归重新拉取
        return wrapLoading(fn,message,...args)
    }
  }

  module.exports = {
    wrapLoading
  }